/*
 * Copyright 2010-2012 Susanta Tewari. <freecode4susant@users.sourceforge.net>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package provider.impl.genomemap.map;

import commons.provider.ProviderException;
import commons.provider.impl.BaseProviderImpl;
import genomemap.map.GeneticMapFunction;
import genomemap.provider.Providers;

/**
 *
 *
 * @version 1.3.0
 * @author Susanta Tewari
 * @history Created on 3/17/13
 * @since 1.3.0
 */
public class GeneticMapFunctionPIs {

    /**
     * Mapping Function:
     * {@code
     *   d = -1/2 * ln(1-2r)
     * }
     *
     * @version 1.3.0
     * @since 1.3.0
     * @history Created on 03/17/2013
     * @author Susanta Tewari
     */
    public static class Haldane extends BaseProviderImpl<GeneticMapFunction>
            implements Providers.GeneticMapFunctionProvider {

        @Override
        public GeneticMapFunction create() throws ProviderException {

            return new GeneticMapFunction() {

                @Override
                public double distance(final double r) {
                    return 0.5 * Math.log(1 - 2 * r);
                }
            };
        }
    }

    /**
     *
     * Mapping Function:
     * {@code
     *   d = 1/4 * ln[(1+2r)/(1-2r)]
     * }
     *
     * @version 1.3.0
     * @since 1.3.0
     * @history Created on 03/17/2013
     * @author Susanta Tewari
     */
    public static class Kosambi extends BaseProviderImpl<GeneticMapFunction>
            implements Providers.GeneticMapFunctionProvider {

        @Override
        public GeneticMapFunction create() throws ProviderException {

            return new GeneticMapFunction() {

                @Override
                public double distance(final double r) {
                    return 0.25 * Math.log((1 + 2 * r) / (1 - 2 * r));
                }
            };
        }
    }
}
